﻿Shader "Hidden/MagicPenShader"
{
    Properties
    {

    }
    SubShader
    {
        Tags { "Queue"="Transparent" }
        LOD 100
        Cull Off ZWrite Off ZTest Always Fog{ Mode Off }

        Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            sampler2D _BackgroundTex;
            sampler2D _LineMaskTex;
            float2 _BackgroundScale;
            float4 _Color;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = v.vertex;
                o.vertex.y = -v.vertex.y;
                o.uv = v.uv;
                return o;
            }

            float4 frag (v2f i) : SV_Target
            {
                float4 col = tex2D(_BackgroundTex, i.uv * _BackgroundScale);
                float4 mask = tex2D(_LineMaskTex, i.uv);
                col.rgb *= _Color.rgb;
                col.a *= mask.a;
                return col;
            }
            ENDCG
        }
    }
}
